package com.shuai.analysis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuai.analysis.domain.entity.Prompt;
import com.shuai.analysis.service.PromptService;
import com.shuai.analysis.mapper.PromptMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author bxs
 * @description 针对表【prompt】的数据库操作Service实现
 * @createDate 2024-07-15 15:15:42
 */
@Service
@Slf4j
public class PromptServiceImpl extends ServiceImpl<PromptMapper, Prompt>
        implements PromptService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PostConstruct
    public void run() throws Exception {
        List<Prompt> list = this.list();
        for (Prompt prompt : list) {
            log.info("加载了prompt-key:{} 到缓存中", prompt.getStoreKey());
            stringRedisTemplate.opsForValue().set(prompt.getStoreKey(), prompt.getContent());
        }
    }
}




